#include "log.h"

/**
 * @msg: 获取时间戳
 * @param {void} 
 * @return: string
 */
string LOG::timeStamp()
{
    std::time_t result = std::time(nullptr);
    return std::asctime(std::localtime(&result));
}

/**
 * @msg: 输出信息到日志
 * @param {msg, statu}
 * @return: void
 */
void LOG::logPrint(string msg, LogStatu statu)
{
    static LogSystem log_file;
    switch (statu)
    {
    case LOG::MSG:
        log_file << "MSG: " + msg + " --Time: " + timeStamp();
        break;
    case LOG::WARNING:
        log_file << "WARNING: " + msg + " --Time: " + timeStamp();
        break;
    case LOG::ERROR:
        log_file << "ERROR: " + msg + " --Time: " + timeStamp();
        break;
    }
}

void LOG::LogSystem::operator << (std::string data)
{
    //写入日志文件末尾
    p_outfile.open("./data/log.txt", std::ios::app);
    p_outfile << data;
    p_outfile.close();
}